home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / d3_shade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  1.6 KB  |  71 lines

  1. /*****************************************************************************
  2.   FILE           : d3_shade.c
  3.   SHORTNAME      : shade.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : illumination of an unit
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Ralf Huebner
  10.   DATE           : 1.12.1991
  11.  
  12.   CHANGED BY     :
  13.   IDENTIFICATION : @(#)d3_shade.c    1.8 3/2/94
  14.   SCCS VERSION   : 1.8
  15.   LAST CHANGE    : 3/2/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21. #include <X11/Xlib.h>
  22. #include <X11/Intrinsic.h>
  23.  
  24. #include "glob_typ.h"
  25.  
  26. #include <math.h>
  27.  
  28. #include "d3_global.h"
  29. #include "d3_anageo.h"
  30.  
  31. #include "d3_shade.ph"
  32.  
  33.  
  34. /*****************************************************************************
  35.   FUNCTION : d3_shadeIntens
  36.  
  37.   PURPOSE  : calculate the light intensity for a given polygon
  38.   RETURNS  : -1.0 <= intensity <= 1.0
  39.   NOTES    : 
  40.  
  41.   UPDATE   :
  42. ******************************************************************************/
  43.  
  44. void d3_shadeIntens (float *intens, float *v1, float *normal, float *lp)
  45.  
  46. {
  47.      vector lv;
  48.      float cos_a;
  49.      int i;
  50.  
  51.      for (i=0; i<3; i++)
  52.          lv[i] = v1[i] + lp[i];
  53.      lv[3] = sqrt (lv[0]*lv[0] + lv[1]*lv[1] + lv[2]*lv[2]);
  54.  
  55.      cos_a = (normal[0] * lv[0] + normal[1] * lv[1] + normal[2] * lv[2]) /
  56.              (normal[3] * lv[3]);
  57.  
  58.      *intens = d3_state.light.Ia * d3_state.light.Ka;
  59.      if (cos_a < 0.0)
  60.          *intens -= d3_state.light.Ip * d3_state.light.Kd * cos_a;
  61.      if (*intens > 1.0)
  62.          *intens = 1.0;
  63.      if (*intens < -1.0)
  64.          *intens = -1.0;
  65. }
  66.  
  67.  
  68.  
  69. /* end of file */
  70. /* lines: 68 */
  71.